import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import './assets/styles/main.scss'

// 创建一个简单的模拟Electron API
window.electronAPI = {
  onMenuAction: (callback) => {
    window.addEventListener('menu-action', (e: any) => callback(e.detail))
  },
  removeMenuActionListener: () => {},
  fileOperation: async () => ({ success: true }),
  openWindow: () => {},
  platform: navigator.platform,
  onMessage: () => {},
  minimizeWindow: () => console.log('最小化窗口'),
  maximizeWindow: () => console.log('最大化窗口'),
  closeWindow: () => console.log('关闭窗口')
}

// 提供触发菜单事件的方法，方便开发测试
window.triggerMenuAction = (action) => {
  window.dispatchEvent(new CustomEvent('menu-action', { detail: { action } }))
}

// 创建应用实例
const app = createApp(App)

// 全局属性：添加模拟的Electron API
app.config.globalProperties.$electronAPI = window.electronAPI

// 使用插件
app.use(createPinia())
app.use(router)

// 挂载应用
app.mount('#app')

// 打印启动信息
console.log(`
=================================================
    应用已在Web模式下启动
    此模式下使用的是模拟的Electron API
    可以通过控制台的window.triggerMenuAction
    方法触发菜单事件进行测试
=================================================
`)

// 类型声明
declare global {
  interface Window {
    electronAPI: any;
    triggerMenuAction: (action: string) => void;
  }
}
